
<template>
  <el-button type="primary" @click="increase(props)">神经内科一诊室叫号</el-button>
  <el-table :data="tableDataFromDB.slice((currentPage - 1) * pagesize, currentPage * pagesize)" height="95" border style="width: 100%">
    <el-table-column fixed prop="nowregisterId" label="目前就诊人序号" width="150" />
    <!-- <el-table-column prop="nextregisterId" label="患者序号" width="150" /> -->
    <el-table-column prop="noVisit" label="今日未就诊人数" width="150" />
    
     
    <el-table-column fixed="right" label="操作" width="200">
      <template #default="row">
        <!-- 编辑按钮 -->

        <el-button type="success" @click="handleClick(row)" style="">
          <el-icon><Edit /></el-icon>
        </el-button>
        
      </template>
    </el-table-column>
  </el-table>
  <!-- <el-pagination
        layout="total,sizes,prev,pager,next,jumper"
        :total="tableDataFromDB.length"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[10,20,30,40]"
        :page-size="pagesize"/> -->
  
  <!-- 编辑对话框 -->
  <el-dialog v-model="dialogVisible" title="编辑" width="30%">
    <el-form label-width="120px">
      <el-form-item label="当前就诊人序号">
        <el-input v-model="info_edit.nowregisterId" />
      </el-form-item>
    </el-form>
    <el-form label-width="120px">
      <el-form-item label="今日未就诊人数">
        <el-input v-model="info_edit.noVisit" />
      </el-form-item>
    </el-form>
    <!-- <el-form label-width="120px">
      <el-form-item label="下一个就诊人序号">
        <el-input v-model="info_edit.nextregisterId" />
      </el-form-item>
    </el-form> -->
    
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="dialogVisible = false">取消</el-button>
        <el-button type="primary" @click="revise()" v-model="dialogVisible"
          >确认</el-button
        >
      </span>
    </template>
  </el-dialog>
</template>


<script>
import { ElMessage } from 'element-plus'
import { get } from '@/utils/request'
//import { ElMessage } from 'element-plus/lib/components'
//用于网页初始化，网页启动时会自动执行该函数mounted()
//res:从该url地址返回的对象 真正的数据在res.data中，res.data是数组
//import { get } from '@/utils/request'
export default {
  data() {
    return {
      currentPage: 1, //默认页码为1
      pagesize: 10, //默认一页显示10条
      dialogVisible: false,
      dialogVisible_add: false, //添加科室窗体的可见性

      info_edit: {},
      info_add: {},
      tableDataFromDB: [] //空数组
    }
  },

  //挂载函数,网页启动时会自动执行该函数,用与网页初始化
  //res：从该url地址返回的数据
  mounted() {
    get('/getNowregister').then((res) => {
      console.log(res)
      this.tableDataFromDB = res.data
      console.log(this.tableDataFromDB)
    })
  },
  methods: {
     handleSizeChange (size) {
      console.log(size,'size');
      this.pagesize = size;
      console.log(this.pagesize); //每页下拉显示数据
    },
    handleCurrentChange (currentPage) {
      console.log(currentPage,'currentPage');
      this.currentPage = currentPage;
      console.log(this.currentPage); //点击第几页
    },
    increase() {
      this.dialogVisible_add = !this.dialogVisible_add
    },
    

    //编辑方法，
    handleClick(data) {
      this.info_edit = data.row //把数据放到info里边
      //打印info
      // console.log(this.info_edit)
      this.dialogVisible = !this.dialogVisible
    },
    //确认编辑方法
    //修改，模拟患者诊毕，叫号
    revise() {
      this.dialogVisible = !this.dialogVisible //马上消失
      //作用是调整下createTime的格式
    //   var dt = new Date(this.info_edit.updateTime)
    //   let year = dt.getFullYear()
    //   let month = dt.getMonth() + 1
    //   let date = dt.getDate()
    //   this.info_edit.updateTime = year + '/' + month + '/' + date
       get('/updateNowregister', this.info_edit).then((res) => {
         ElMessage({
          message: '修改成功！',
          type: 'success'
        })
        //window.location.reload()
      })
    },

    
  }
}
</script>
